#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e7 + 5;

int n, m;
int a[N];
struct Node {
  int val, rank;
  int ch[2];
} tr[N];
int root;
#define lc(p) tr[p].ch[0]
#define rc(p) tr[p].ch[1]
int newnode(int val, int rank) {
  static int tot = 0;
  ++tot;
  tr[tot].val = val;
  tr[tot].rank = rank;
  return tot;
}
int st[N], top;
void insert(int val, int rank) {
  int x = newnode(val, rank);
  while (top) {
    int y = st[top];
    if (tr[y].rank < tr[x].rank)
      break;
    else {
      tr[x].ch[0] = y;
      top--;
    }
  }
  if (top) {
    tr[st[top]].ch[1] = x;
  } else {
    root = x;
  }
  st[++top] = x;
}
ll ans1, ans2;
void dfs(int p) {
  if (!p) return;
  ll x = 1ll * tr[p].val * (tr[lc(p)].val + 1);
  ll y = 1ll * tr[p].val * (tr[rc(p)].val + 1);
  ans1 ^= x;
  ans2 ^= y;
  dfs(lc(p));
  dfs(rc(p));
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  rep(i, 1, n) cin >> a[i];
  rep(i, 1, n) insert(i, a[i]);
  dfs(root);
  cout << ans1 << ' ' << ans2;
  return 0;
}